﻿/*
 * Created on 2006-2-15
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.wsj.util.page;

import java.util.List;

/**
 * @author admin
 * 分页
 * 
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class PageResultSet implements java.io.Serializable {
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = -2451193307766447415L;

	/**
	 * 默认每页显示得页数
	 */
	public final static int PAGESIZE = 10;

	/**
	 * 记录总数
	 */
	private int recordNum;
	
    /**
     * 当前页
     */
	private int curPage;

	/**
	 * 开始行
	 */
	private int startRow;

	/**
	 * 行数
	 */
	private int rowNum;

	/**
	 * 每页显示得页数
	 */
	private int pageSize;

	/**
	 * 记录集
	 */
	private List result;

	public int getRecordNum() {
		return recordNum;
	}

	public void setRecordNum(int recordNum) {
		this.recordNum = recordNum;
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		if (curPage < 1)
			this.curPage = 1;
		else
			this.curPage = curPage;
	}

	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public int getRowNum() {
		return rowNum;
	}

	public void setRowNum(int rowNum) {
		this.rowNum = rowNum;
	}

	public PageResultSet() {
		this.pageSize = PAGESIZE;
	}

	public PageResultSet(int pageS) {
		pageSize = pageS;
	}

	public int getAllPage() {
		int allPage = recordNum / pageSize;
		if (recordNum % pageSize != 0)
			allPage++;
		if (allPage == 0)
			allPage = 1;
		return allPage;
	}

	public int getEndRow() {
		int endRow = startRow + pageSize - 1;
		if (endRow > recordNum)
			endRow = recordNum;
		return endRow;
	}

	public int getNextPage() {
		if (curPage >= getAllPage())
			return getAllPage();
		else
			return curPage + 1;
	}

	public int getBackPage() {
		if (curPage <= 1)
			return 1;
		else
			return curPage - 1;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List getResult() {
		return result;
	}

	public void setResult(List result) {
		this.result = result;
	}

}
